<?php
require_once 'modules/event/const.inc';
class Helper_Blog extends Zend_Controller_Action_Helper_Abstract
{
	private $userBlogCounts = array();
	
	
	private function getOtherHelper($helperName){
		return Zend_Controller_Action_HelperBroker::getStaticHelper($helperName);
	}
	
    public function getUserBlogs($uid, $page=0, $limit=20){
        $networkModel = AppGlobal::loadModel('My', 'blog');
        $blogs = $networkModel->getMyBlog($uid, 'all', $page, $limit);
        $pageInfo = $networkModel->getPageInfo();
        $this->userBlogCounts[$uid] = $pageInfo['total_item'];
        return $blogs;
    }
    
    public function getUserBlogCount($uid){
    	if(count($this->userBlogCounts) > 0 && isset($this->userBlogCounts[$uid]))
    		return $this->userBlogCounts[$uid];
    	$blogModel = AppGlobal::loadModel('My', 'blog');
        return $blogModel->getCountMyBlog($uid);
    }
    
    public function getNetworkBlog($nwid, $page=0, $limit=20){
    	$blogModel = AppGlobal::loadModel('Blog', 'blog');
        return $blogModel->getNetworkBlog($nwid, $page, $limit);
    }
    
	public function getNetworkBlogCount($nwid){
    	$blogModel = AppGlobal::loadModel('Blog', 'blog');
        return $blogModel->getNetworkBlogCount($nwid);
    }
    
	public function isCanAdd($type, $eid, $uid){
		
		Zend_Controller_Action_HelperBroker::addPath(APPLICATION_PATH . '/modules/blog/helpers', 'Helper');
		$privacyHelper = $this->getOtherHelper('privacy');
		return $privacyHelper->isCanAdd($type, $eid, $uid);
	}
}

